<?php
declare(strict_types=1);

namespace App\Controller\v1;

use App\Controller\AbstractController;

use App\Request\Web\SignInRequest;
use App\Service\Web\UserSignInService;
use App\Service\Web\UsersService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\Resource\Json\JsonResource;


#[Controller(prefix: '/api/web/v1')]
class UserSignInController extends AbstractController
{
    #[Inject]
    private UserSignInService $userSignService;

    /**
     * 签到
     * @return JsonResource
     */
    #[PostMapping('user_sign/in')]
    public function signIn()
    {
        $result = $this->userSignService->signIn();
        return new JsonResource($result);
    }

    /**
     * 连续签到天数
     * @return JsonResource
     */
    #[GetMapping('user_sign/continuous_days')]
    public function getContinuousDays()
    {
        $result = $this->userSignService->getContinuousDays();
        return new JsonResource(['days' => $result]);
    }
    /**
     * 总签到天数
     * @return JsonResource
     */
    #[GetMapping('user_sign/total_sign_in_days')]
    public function getTotalSignInDays()
    {
        $result = $this->userSignService->getTotalSignInDays();
        return new JsonResource(['days' => $result]);
    }

    /**
     * 本月签到数
     * @return JsonResource
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */

    #[PostMapping('user_sign/month_date')]
    public function getMonthSignInData()
    {
        $request = $this->container->get(SignInRequest::class);
        $data = $request->scene('month_sign_num')->validated();
        $result = $this->userSignService->getMonthSignInData($data['month']);
        return new JsonResource(['days' => $result]);
    }

    /**
     * 签到排行榜
     * @return JsonResource
     */
    #[GetMapping('user_sign/today_rank')]
    public function getTodayRank()
    {
        $result = $this->userSignService->getTodayRank();
        return new JsonResource(['days' => $result]);
    }
}